<?php
class User extends ProcessingDate{
	protected $id;
	protected $login;
	protected $password;
	protected $name;
	protected $email;	
	protected $hourlyLoad;
	protected $dateCreated;
	protected $dateExit;
	protected $status;
	protected $date;
	
	//Propriedades Extras
	protected $group;
	protected $idGroup;
	protected $titelGroup;
	protected $fieldsDBObj;
	protected $fieldsDB;

	function __construct(){
		$this->fieldsDB['id']			= "id_usuario";
		$this->fieldsDB['login']		= "login";
		$this->fieldsDB['password']		= "senha";
		$this->fieldsDB['name']			= "nome";
		$this->fieldsDB['email']		= "email";
		$this->fieldsDB['hourlyLoad']	= "carga_horaria";
		$this->fieldsDB['dateCreation']	= "data_criacao";
		$this->fieldsDB['dateExit']		= "data_saida";
		$this->fieldsDB['status']		= "status";	
		$this->fieldsDB['date']			= "data";
	}
	
	public function __set($name, $value) {		
		//Seta os dados do mapeamento do banco.
		if($this->fieldsDB[$name] != "")
			$this->fieldsDBObj[$this->fieldsDB[$name]] = $value;

		//Seta o atributo.
		if($name == "id")
			$this->setId($value);
		elseif($name == "userGroup")
			$this->setGroup($value);
		elseif($name == "listModules")
			$this->setListModules($value);
		else
			$this->$name = $value;
	}
	
	protected function setDefaultError(){
		trigger_error('Não é possível trocar o ID do usuário'); 
	}
	
	public function setGroup(UserGroup $obj){		
		if($obj != NULL)
			$this->group = $obj;
	}
	
	/*GET METODOS*/	
	public function __get($name) {		
		if($name == "id"){
			return $this->getId();
		}else if($name == "group"){
			return $this->getGroup();
		}else if($name == "listModules"){
			return $this->getListModules();
		}else{
			return $this->$name;
		}
	}
	
	public function getGroup(){		
		if(isset($this->group))
			return $this->group;
		else
			return NULL;
	}
	
	public function getListModules(){		
		if(isset($this->listModules) && count($this->listModules) > 0)
			return $this->listModules;
		else
			return NULL;
	}
}
?>